package com.szss.springbootfirst.mq;

import com.szss.springbootfirst.config.RabbitMQConfig;
import com.szss.springbootfirst.entity.Email;
import com.szss.springbootfirst.service.impl.Send;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import java.util.List;

/**
 * @author wcx
 * @date 2023/2/10 15:45
 */
@Component
public class MessageConsumer {

    @Autowired
    private Send send;

    @RabbitListener(queues = {RabbitMQConfig.QUEUE_EMAIL})
    public void consumerMessage(List<Email> list) throws MessagingException {
        String title = "致何愁小妹妹的一封信";
        String message = "当你看见这封信的时候，I want to say you:"
                +"It's you who decide everything, not anyone. You can control your mood at will.;"
                +"Life is actually a process from exhaustion to happiness. If you can't endure the bitter process, you can only cry by yourself.;"
                +"Inadvertent jokes have quietly revealed too much love."
                +"最后：祝你偷偷打游戏一直连跪！ (一分钟一条关不掉的，九点钟自动结束)";
        for (Email obj:list){
            send.sendMessage(obj.getQq(),title,message);
            System.out.println(obj);
        }
    }
}
